#include "MysqlClient.h"
int main(int argc,char *argv[])
{
//	char* dbip = "172.17.33.31";
	char* dbip = "192.168.3.101";
	mysql_library_init(0,NULL,NULL);
	MYSQL *conn;
	MYSQL_RES *res_set;
	conn = mysql_init(NULL);
	if(conn == NULL)
	{
		fprintf(stderr,"mysql_init failed\n");
		exit(1);
	}
	mysql_options(conn,MYSQL_READ_DEFAULT_GROUP,"MysqlClient-Xddai");
	if (!mysql_real_connect(conn,dbip,"xddai","123456","ConfiguableDBOperator",0,NULL,0))
	{
	    fprintf(stderr, "Failed to connect to database: Error: %s\n",
		          mysql_error(conn));
		mysql_close(conn);
	}

	char *sql="select id from datapolicy";
	if(mysql_query(conn,sql) != 0)
		fprintf(stderr,"query failed\n");
	else
	{
		MYSQL_ROW row;
		int i=0;
		res_set = mysql_store_result(conn);
		if(res_set == NULL)
			fprintf(stderr,"no result set\n");
		else
		{
			int row_number = mysql_num_rows(res_set);
			printf("number of row is %d\n",row_number);
			while((row=mysql_fetch_row(res_set)) != NULL)
			{
				for(i=0;i<mysql_num_fields(res_set);i++)
				{
					if(i>0)
						fputc('\t',stdout);
					printf("%s",row[i]==NULL?"NULL":row[i]);
					fputc('\n',stdout);
				}
				i=0;
			}

		}
	}

	mysql_close(conn);
	mysql_library_end();
}


